/*
    @author: shaqdb1
    description: This is just a short program I made to help me mod games and code certain things faster.
    this is an open source document, and will be for learning purposes. Practice makes perfect, just remember that
    if nothing else. This program will wait in an infinite loop for any key to be inputed, but if you use the
    'ctrl+shift+~' key you will get the value of 'ctrl+shift+~' key and end the program. I am thinking about writing a version
    to actually support hexidecimal conversion, this will absolutely take quite sometime to do so due to testing.

    v1.0:
        support char to hexidecimal using ctrl+h
        support char to decimal if in hex press ctrl+n
        support linux and windows through wine
        added in a custom delay and it takes second
        added in a option switcher help
        note: make sure that you are in decimal mode before you exit program!
        support char to dec conversions
        added version number
*/

#include "main.hpp"
#include "delay_init.hpp"
#include "char_cvt_hex.hpp"
#include "header_refresh.hpp"

int controller = 0; //0 = decimal, 1 = hexidecimal
int header_count = 0; //0 = no refresh, 1 = refresh
int user_help = 1; // 0 = decimal, 1 = hexidecimal

int main ( void )
{

    if ( header_count == 0 )
    {
        header_refresh ( );
        header_count = 1;
    }

    do
    {
        char user_input;

        if ( controller == 0 && user_help == 1)
        {
            cout << "\ndecimal mode..." << endl;
            user_help = 0;
        }

        cin >> user_input; //gets char value
        cout << ( int )( user_input ) << endl; //cast char to int and show result

        /*check if ctrl+shift+~ has been entered, then end program*/
        if ( ( int )( user_input ) == 30 )
        {
          //bye messeage
          cout << "\nThanks for using, and if any bugs email me again at shaqdb1@gmail.com" << endl;
          delay_init ( 2 );
          cout << "\nexiting..." << endl;
          delay_init ( 3 );
          return 1;
        }

        /*switch to hexidecimal conversion*/
        if ( ( ( int )( user_input ) ) == 8 ) //ctrl+h goto hex
        {
            controller = 1;
            user_help = 1;
            char_cvt_hex ( user_input );
        }


    } while ( controller == 0 );

    return 0;
}

void char_cvt_hex ( char input )
{
    do
    {
        if ( controller == 1 && user_help == 1)
        {
            user_help = 0;
            cout << "\nhexidecimal mode..." << endl;
        }

        cin >> input; //get the char value
        cout << "0x" << hex << ( int )( input ) << endl;

        if ( ( int )( input ) == 14 ) //ctrl+n goto decimal
        {
            controller = 0;
            user_help = 1;
            header_count = 1;
            main ( );
        }

    } while ( controller == 1 );
}
